package com.dao;

import com.pojo.User;
import com.utils.DSUtil;

import java.util.ArrayList;
import java.util.List;

public class UserDao {

    public User queryByUsername(String username) {
        ArrayList<User> list = DSUtil.query("select * from user where username = ?", User.class, username);
        if (list != null && list.size() > 0){
            return list.get(0);
        }else {
            return null;
        }
    }

    public int insert(User u) {
        return DSUtil.execute("insert into user(id,username,password,email) values(null,?,?,?)",
                u.getUsername(),u.getPassword(),u.getEmail());
    }


    public int updatePwd(User u) {
        return DSUtil.execute("update user set password = ? where username = ? and email = ?"
                , u.getPassword(),u.getUsername(),u.getEmail());
    }
}
